package com.kun.peng.system.mapper;

import com.kun.peng.mybatis.base.MyBaseMapper;
import com.kun.peng.system.domain.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * Created on 2021/11/17.
 *
 * @author xuebaopeng
 * Description
 */
@Mapper
public interface UserMapper extends MyBaseMapper<User> {


    List<User> findByRoleId(Long roleId);

    /**
     * 根据角色中的部门查询
     * @param deptId
     * @return
     */
    List<User> findByRoleDeptId(Long deptId);

    /**
     * 根据菜单查询
     * @param menuId 菜单ID
     * @return
     */
//    @Select(value = "SELECT u.* FROM sys_user u, sys_users_roles ur, sys_roles_menus rm WHERE u.user_id = ur.user_id AND ur.role_id = rm.role_id AND rm.menu_id = #{menuId} group by u.user_id")
    List<User> findByMenuId(@Param("menuId")Long menuId);


    /**
     * 根据用户名查询
     * @param userName 用户名
     * @return
     */
     User findByUsername(@Param("userName")String userName);


    /**
     * 修改密码
     * @param userName 用户名
     * @param pass 密码
     * @param lastPasswordResetTime
     */
    @Update(value = "update sys_user set password = #{password} , pwd_reset_time = #{lastPasswordResetTime} where username = #{userName}")
    void updatePass(@Param("userName")String userName, @Param("password")String pass, @Param("lastPasswordResetTime")Date lastPasswordResetTime);

    int countByDepts(Set<Long> deptIds);
}
